<template>
    <div>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>文章搜索</span>
            </div>
            <div class="w-full ">
                <hd-alert :alert="{type:'warning'}" class="mb-2">请输入标题关键字</hd-alert>
                <el-input prefix-icon="el-icon-search" v-model="word" placeholder="文章标题关键字" @change="search"
                          class="mb-3"></el-input>
            </div>

            <el-table
                :data="form"
                border
                style="width: 100%">
                <el-table-column
                    prop="article_id"
                    label="类型ID"
                    width="180">
                </el-table-column>
                <el-table-column
                    #default="{row:r}"
                    label="类型名称"
                >
                    {{ r.cname }}
                </el-table-column>
                <el-table-column
                    prop="id"
                    label="文章ID"
                    width="180">
                </el-table-column>
                <el-table-column
                    prop="title"
                    label="标题"
                    width="180">
                </el-table-column>
                <el-table-column
                    #default="{row:r}"
                    label="操作"
                >
                    <el-button type="primary" size="small" @click="show(r.cname,r.id)">点击查看</el-button>
                </el-table-column>

            </el-table>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            form: [],
            word: '房',
            data: {word: '房'}
        }
    },
    route: {path: 'admin/search'},
    async created() {
        this.form = await this.axios.get('search/default')
    },
    methods: {
        async search() {
            this.form = await this.axios.post('search/search', this.data)
        },
        show(cname, id) {
            cname = cname.toLowerCase();
            this.$router.push({path: `/${cname}/${id}/show`})
        }
    }
}
</script>

<style scoped>

</style>
